package com.xyh.flowershop.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author 小约翰可汗
 * @className OrderStatusEnum
 * @description 订单状态枚举类
 * @createTime 2024/5/2116:17
 */
@Getter
public enum OrderStatusEnum {

    UNPAID(0, "待付款"),
    UNCONFIRMED(1, "待确认"),
    //已确认
    CONFIRMED(2, "已确认"),
    // 待发货
    UNDELIVERED(3, "待发货"),
    // 已发货
    DELIVERED(4, "已发货"),
    // 待收货
    UNRECEIVED(5, "待收货"),
    // 已确认收货
    RECEIVED(6, "已收货"),
    // 已取消
    CANCELLED(7, "已取消"),
    // 错误
    ERROR(8, "错误");

    private static Map<Integer, OrderStatusEnum> map = new HashMap<>();

    static {
        for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) {
            map.put(orderStatusEnum.code, orderStatusEnum);
        }
    }

    public static OrderStatusEnum fromCode(Integer code) {
        if(Objects.isNull(code)){
            return ERROR;
        }
        return map.get(code);
    }



    private Integer code;
    private String desc;

    OrderStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

}
